package com.lc.qianrenshiye.conn;

import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/11/28.
 */
@HttpInlet(Conn.GOODS_TYPE)
public class GoodsTypeGet extends BaseAsyGet<GoodsTypeGet.GoodsTypeEntity> {

    public String sid;

    public GoodsTypeGet(AsyCallBack<GoodsTypeEntity> asyCallBack) {
        super(asyCallBack);
    }

    @Override
    protected GoodsTypeEntity parser(JSONObject object) throws Exception {

        TOAST = object.optString("message");

        if (object.optInt("code") == 200) {

            GoodsTypeEntity goodsTypeEntity = new GoodsTypeEntity();

            JSONArray array = object.optJSONArray("list");

            for (int i = 0; i < array.length(); i++) {

                GoodsType goodsType = new GoodsType();

                JSONObject typeObject = array.optJSONObject(i);

                goodsType.id = typeObject.optString("id");
                goodsType.sid = typeObject.optString("sid");
                goodsType.title = typeObject.optString("title");

                goodsTypeEntity.goodsTypeList.add(goodsType);

            }

            return goodsTypeEntity;

        }

        return null;
    }

    public static class GoodsTypeEntity {

        public List<GoodsType> goodsTypeList = new ArrayList<>();
    }

    public static class GoodsType {

        public String id, sid, title;

    }

}
